import types
import logging


__info = {'result':True, 'inited':False}

__upload_files = set()

__result_types = set(['xunit', 'general'])

__upload_case_files = []

__message = ""

__mail_addtional_content = []

__addtional_mail_receiver = ""

class CaseResultFile():
    def __init__(self):
        self.resluttype = None
        self.filename = None

def CommitResut(result):
    if  not isinstance(result, types.BooleanType):
        raise ValueError('result must be bool')
    
    __info['inited'] = True
    __info['result'] = result
    
    
def GetResult():
    if __info['inited'] == False:
        logging.warn('result not be inited default true')
    return __info['result']

def CommitFile(filename):
    if not isinstance(filename, types.StringTypes):
        raise ValueError('filename must be string')
    
    __upload_files.add(filename)
    
    
def CommitMessage(message):
    if not isinstance(message, types.StringTypes):
        raise ValueError('filename must be string')
    global __message
    __message = __message + '\n' + message
    

def CommitMailAddtionalContent(filename):
    if not isinstance(filename, types.StringTypes):
        raise ValueError('filename must be string')
    
    __mail_addtional_content.append(filename)
    
def GetMessage():
    global __message
    return __message

    
def GetUploadFiles():
    return __upload_files


def CommitCaseResultFile(reulttype, filename):
    if reulttype  not in __result_types:
        raise ValueError('result type in not support')
     
    if not isinstance(filename, types.StringTypes):
        raise ValueError('filename must be string')
    
    crf = CaseResultFile()
    crf.resluttype = reulttype
    crf.filename = filename
    
    __upload_case_files.append(crf)    
    

def GetCaseResultFiles():
    return __upload_case_files

def GetMailAddtionalContent():
    return __mail_addtional_content

def SetAddtionanlMailReceiver(receiver):
    if not isinstance(receiver, types.StringTypes):
        raise ValueError('receiver type must be string')
    global __addtional_mail_receiver
    __addtional_mail_receiver = receiver
    
def GetAddtionanlMailReceiver():
    global __addtional_mail_receiver
    return __addtional_mail_receiver 